﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using WebApp.BaseDataSvc;

namespace WebApp
{
    public partial class QOrderFrm : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //AjaxPro.Utility.RegisterTypeForAjax(typeof(QOrderFrm), this);
            //WebCommon.CheckLogin(this, 0);
        }

        [AjaxPro.AjaxMethod]
        public ReturnDatas<DataExt> GetList(string strDeleteFlag, string orderCode, string cCode, string strSDate, string strEDate,
            string orderStatus, string strAgent, string strBizMan, string strStowageMethod, string clientName, string strIsDrawback,
            string customsStatus, string checkOffCode, string caseCode, int pageSize, int pageIndex)
        {
            int recordCount = 0;
            int pageCount = 0;
            ReturnDatas<DataExt> dls = new ReturnDatas<DataExt>();
            dls.RecordCount = recordCount;
            dls.PageCount = pageCount;
            try
            {
                bool? deleteFlag = null;
                DateTime? sDate = null;
                DateTime? eDate = null;
                int? agent = null;
                int? bizMan = null;
                int? stowageMethod = null;
                bool? isDrawback = null;
                WebApp.BaseDataSvc.TB_User user = Session["User"] as WebApp.BaseDataSvc.TB_User;
                var datas = this.BaseDataProxy.FindOrders2(out recordCount, out pageCount, deleteFlag, orderCode, cCode, sDate, eDate, orderStatus, agent, bizMan,
                    stowageMethod, clientName, isDrawback, customsStatus, checkOffCode, caseCode, user.id, user.role, pageSize, pageIndex);
                if (datas != null)
                {
                    List<DataExt> lst = new List<DataExt> { };
                    foreach (var d in datas)
                    {
                        string oPHtml = string.Empty;
                        if (WebCommon.IsActionPermit(this, YY.Common.EnumCommon.PermissionOpType.Update))
                            oPHtml = string.Format("<a href=\"#\" onclick=\"viewUser(false,{0})\">编辑</a> ",d.OrderId);
                        if (WebCommon.IsActionPermit(this, YY.Common.EnumCommon.PermissionOpType.Delete))
                            oPHtml += string.Format("<a href=\"#\" onclick=\"delUser({0})\">删除</a> ", d.OrderId);

                        lst.Add(new DataExt(d,oPHtml));
                    }
                    dls.DataList = lst;
                }
            }
            catch { }
            return dls;
        }

        public class ReturnDatas<T>
        {
            public List<T> DataList { get; set; }
            public int RecordCount { get; set; }
            public int PageCount { get; set; }
        }

        public class DataExt : WebApp.BaseDataSvc.QOrder
        {
            public DataExt(WebApp.BaseDataSvc.QOrder _DataObj, string _OPHtml) { this.DataObj = _DataObj; this.OPHtml = _OPHtml; }
            public WebApp.BaseDataSvc.QOrder DataObj { get; set; }
            //public DataExt(string _OPHtml) {this.OPHtml = _OPHtml; }
            public string OPHtml { get; set; }
        }
    }
}
